//
// RS Game Framework
// Copyright © 2009 Jedd Haberstro
// jhaberstro@gmail.com
// 
// $Id:
//

#ifndef RS_MUTEX_HPP
#define RS_MUTEX_HPP

#include "rs/Portability.hpp"
#include "rs/SmartPointer.hpp"

namespace rs
{
    namespace internal
    {
        class MutexImplementation;
    }
    
    class Condition;
    class Mutex
    {
        friend class internal::MutexImplementation;
        friend class Condition;
        
    private:
        
        typedef SmartPointer< internal::MutexImplementation > MutexImplementationPtr;
        
    public:
        
        Mutex();
        
        Mutex(Mutex const& other);
        
        ~Mutex();
        
        void Lock();
        
        Boolean TryLock();
        
        void Unlock();
        
        Boolean IsLocked() const;
        
        void Swap(Mutex& other);
        
        Mutex& operator=(Mutex const& other);
        
    private:
        
        MutexImplementationPtr implementation_;
        Boolean locked_;
    };
    
    
    inline Boolean Mutex::IsLocked() const {
        return locked_;
    }
}

#endif // RS_MUTEX_HPP
